/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package doan.quanlycanbo.portlet.service.impl;

import java.util.List;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.ResourceConstants;

import doan.quanlycanbo.portlet.NoSuchgiaoducphothongException;
import doan.quanlycanbo.portlet.model.giaoducphothong;
import doan.quanlycanbo.portlet.service.base.giaoducphothongLocalServiceBaseImpl;

/**
 * 
 * @author Nguyen Tuan Vinh
 */
public class giaoducphothongLocalServiceImpl
	extends giaoducphothongLocalServiceBaseImpl {
	
	public List<giaoducphothong> getAll() throws SystemException{
		return giaoducphothongPersistence.findAll();
	}
	
	public giaoducphothong addGDPT(giaoducphothong gtpt1, long userId) throws SystemException{
		long magiaoducphothong = CounterLocalServiceUtil.increment(giaoducphothong.class.getName());
		giaoducphothong gdpt2 = giaoducphothongPersistence.create(magiaoducphothong);
		gdpt2.setGroupId(gtpt1.getGroupId());
		gdpt2.setCompanyId(gtpt1.getCompanyId());
		gdpt2.setLanguageId(gtpt1.getLanguageId());
		gdpt2.setTengdpt(gtpt1.getTengdpt());
		
		try {
			resourceLocalService.addResources(gtpt1.getCompanyId(), gtpt1.getGroupId(), userId, 
					giaoducphothong.class.getName(), gdpt2.getPrimaryKey(), false, true, true);
		} catch (PortalException e) {
			e.printStackTrace();
		}
		
		return giaoducphothongPersistence.update(gdpt2, false);
	}
	
	public giaoducphothong updateGDPT(long magiaoducphothong, String tengdpt) throws SystemException, NoSuchgiaoducphothongException{
		giaoducphothong gdpt = giaoducphothongPersistence.findByPrimaryKey(magiaoducphothong);
		gdpt.setTengdpt(tengdpt);
		return giaoducphothongPersistence.update(gdpt, false);
	}
	
	public giaoducphothong deleteGDPT(long magiaoducphothong) throws SystemException, NoSuchgiaoducphothongException,PortalException{
		giaoducphothong gdpt = giaoducphothongPersistence.findByPrimaryKey(magiaoducphothong);
		return deleteGDPT(gdpt);
	}
	
	public giaoducphothong deleteGDPT(giaoducphothong gdpt) throws SystemException,PortalException{
		resourceLocalService.deleteResource(gdpt.getCompanyId(), giaoducphothong.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, gdpt.getPrimaryKey());
		return giaoducphothongPersistence.remove(gdpt);
	}
}